﻿using System;

namespace NEnsure.Rules
{
	public class MinLengthRule : BaseBusinessRule<int>, IBusinessRule<string>
	{
		private readonly int _minLength; 

		public override string RuleKey
		{
			get { return "Min-Length Rule"; }
		}

		public MinLengthRule(int minLength)
			: base("Property {key} can be no less than " + minLength + " characters long. You entered: {value}")
		{
			if (minLength < 0)
			{
				throw new ArgumentException("Min length can't be less than 0.", "minLength");	
			}

			_minLength = minLength;
		}

		public bool IsBrokenBy(string value)
		{
			if (string.IsNullOrEmpty(value))
			{
				return false;
			}

			return value.Length < _minLength;
		}
	}
}
